import java.io.DataInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;

/**
 * Created by lrs on 2018/1/4.
 */
public class Network {

    public static void get(String url, String fileName) {
        System.out.println("下载缺失资源：" + url + " 保存到：" + fileName);

        URL con = null;
        try {
            con = new URL(url);
            DataInputStream dataInputStream = new DataInputStream(con.openStream());
            FileOutputStream fileOutputStream = new FileOutputStream(new File(fileName));

            byte[] buffer = new byte[1024];
            int length;

            while ((length = dataInputStream.read(buffer)) > 0) {
                fileOutputStream.write(buffer, 0, length);
            }

            dataInputStream.close();
            fileOutputStream.close();
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
